package com.chen.blog.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chen.blog.common.api.CommonResult;
import com.chen.blog.mapper.CollectMapper;
import com.chen.blog.model.Collect;
import com.chen.blog.service.CollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author chen
 * @since 2022-01-24
 */
@Service
@Transactional
public class CollectServiceImpl extends ServiceImpl<CollectMapper, Collect> implements CollectService {

    @Autowired
    private CollectMapper collectMapper;

    /**
     * 检索指定用户的收藏列表功能实现
     *
     * @param id
     * @param currentPage
     * @param pageSize
     * @param map
     * @return
     */
    @Override
    public CommonResult getCollect(Integer id, Integer currentPage, Integer pageSize, Map<String, Object> map) {
        if (currentPage <= 0) {
            currentPage = 0;
        } else {
            currentPage *= pageSize;
        }
        Map<String, Object> result = new HashMap<>();
        result.put("total", collectMapper.getCollectCount(id, map));
        result.put("blog", collectMapper.getCollect(id, currentPage, pageSize, map));
        return CommonResult.success(null, result);
    }
}
